package net.tv90.bfmccore.command;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class RankCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        //设置玩家军衔
        if (label.equalsIgnoreCase("setrank")) {
            if (args.length == 0) {
                sender.sendMessage("/setrank 0 <玩家>    设置军衔为0并取消所有军衔解锁权限");
                sender.sendMessage("/setrank <等级> <玩家>    设置军衔解锁权限到指定等级,但不会修改玩家的军衔");
            }

            int rankIndex = Integer.parseInt(args[0]);

            String player = args[1];

            for (int i = rankIndex + 1; i <= 140; i++) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + player + " permission unset fms.rank." + i);
            }
            sender.sendMessage("已取消玩家" + player + "军衔" + rankIndex + "级之后的解锁权限");

            for (int i = 1; i <= rankIndex; i++) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + player + " permission set fms.rank." + i);
            }
            sender.sendMessage("已给予玩家" + player + "军衔" + rankIndex + "级之前的解锁权限");

            if (rankIndex == 0) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "points set " + player + " 0");
                sender.sendMessage("已设置玩家" + player + "军衔为0并清除所有解锁权限");
            }
            return true;
        }

        return true;
    }
}
